﻿
//双击事件
function CustomDbClick() {
    //parent.closeWin(); //去掉双击功能
    fnViewDetail();
}


//添加信息
var fnCustomAdd = function () {
    const_EditEntity = "ExaminationPlan";
    var pagetitle = "新增考核计划";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=add"));
    parent.NeedRefreshPage = this;

}

//修改信息
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "ExaminationPlan";
    //debugger
    var pagetitle = "修改考核计划_" + record._oData["Caption"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=edit" + "&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;
}

//删除第一步
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        //this.getRecordSet()._records[0]._oData["BarItem"]
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }

    var id = record.getData(const_entityID);
    //第一步先删除相关的引用表信息、子表、主表
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=deleExaminationPlan" + "&json=" + elist.join(","), {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                        SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                        YAHOO.example.container.dialog3.show();
                    }
                }
                else {
                    alert(str);
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}

//查看
var fnViewDetail = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "ExaminationPlan";
    //debugger;
    var pagetitle = "查看考核计划_" + record._oData["Caption"];
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=view" + "&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;
}

//对应的考核计划ID
var selectPlanID = "";
//适用岗位
var fnSelectPost = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    selectPlanID = record.getData(const_entityID);

    document.getElementById("dialog1_h").innerHTML = "适用岗位";
    document.getElementById("EditUIWindow").src = "../EditWidows/YUITree.aspx?r=" + Math.random() + "&entity=DatPost&masterPara=DatPost|PostName|PostID|ParentID|DeptID|True&IsHighlightUpDown=false&IsExpandAll=true";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    setTimeout(getCheckedNodes, 200);
    //getCheckedNodes();
}

//调用YUITree.aspx的ChooseInfo方法，获取选中部门、岗位
var getChooseInfo = function () {
    var editwindow = document.getElementById("EditUIWindow");
    if (editwindow) {
        editwindow.contentWindow.ChooseInfo();
    }
}

//返回选中岗位
var _fn = function (ids, names) {
    if (ids == "" || ids == "undefined") return;
    //alert("ids:" + ids + "  names:" + names);
    //保存到数据库
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrExaminationAjax.aspx?flag=SaveExaminationObjectByPost&ids=" + ids + "&nams=" + names + "&selectPlanID=" + selectPlanID, {
        success: function (res) {
            try {
                var str = res.responseText;
                //debugger;
                if (str == "1") {
                    alert("保存成功！");
                }
                else {
                    alert("保存失败！");
                }
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
    YAHOO.example.container.dialog1.hide();
}

//得到已经选择的部门或岗位
var getCheckedNodes = function () {
    //debugger;
    var editwindow = document.getElementById("EditUIWindow");
    var request = "../../Extend/AjaxData/DataProcessin.aspx?action=Get&entity=ExaminationObject&condition=PlanID='" + selectPlanID + "'";
    YAHOO.util.Connect.asyncRequest('POST', request, {
        success: function (res) {
            var inventory;
            try {
                //debugger;
                var str = res.responseText;
                var ids = [];
                var items = eval("[" + str + "]");
                for (var i = 0; i < items[0].rows.length; i++) {
                    ids.push(items[0].rows[i].PostID);
                }
                ids = ids.join(",");
                if (editwindow) {
                    editwindow.contentWindow.checkSelectedNode(ids);
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("读取节点数据错误：" + error.statusText);
        }
    }, null);
}

//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {

        var btn = $("#yui-gen7-button");
        btn.click(function () {
            getChooseInfo();
        });

    });
}

//查看明细
var fnLinkSolutionItem = function (elCell, oRecord, oColumn, sData) {
    //debugger;
    elCell.innerHTML = "<a href=\"#\" onclick=\"javascript:fnSolutionItem('" + oRecord.getData("SolutionID") + "','" + sData + "');\">" + sData + "</a>";
};

//打开链接
var fnSolutionItem = function (solutionID, solutionName) {
    var pagetitle = "查看考核方案【" + solutionName + "】";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=ExaminationSolution&fun=view" + "&id=" + solutionID));
    parent.NeedRefreshPage = this;
}





